package com.core.excel.jxl;


import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

public class JxlMain {
    public static void main(String[] args) {
        List<Employee> employees = new ArrayList<>();
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd", Locale.US);
            employees.add(new Employee("Elsa", dateFormat.parse("1970-Jul-10"), 1500, 0.15));
            employees.add(new Employee("Oleg", dateFormat.parse("1973-Apr-30"), 2300, 0.25));
            employees.add(new Employee("John", dateFormat.parse("1970-Jul-10"), 3500, 0.10));
            employees.add(new Employee("Neil", dateFormat.parse("1975-Oct-05"), 2500, 0.00));
            employees.add(new Employee("Maria", dateFormat.parse("1978-Jan-07"), 1700, 0.15));
            employees.add(new Employee("John", dateFormat.parse("1969-May-30"), 2800, 0.20));
            employees.add(new Employee("Oleg", dateFormat.parse("1988-Apr-30"), 1500, 0.15));
            employees.add(new Employee("Maria", dateFormat.parse("1970-Jul-10"), 3000, 0.10));
            employees.add(new Employee("John", dateFormat.parse("1973-Apr-30"), 1000, 0.05));
            //https://blog.csdn.net/weixin_57057153/article/details/134406271
            //非常强大，可以横向和纵向扩展，多sheet
            FileInputStream in = new FileInputStream("C:\\Users\\Administrator\\Desktop\\test\\template.xlsx");
            FileOutputStream out = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\test\\"+System.currentTimeMillis()+".xlsx");
            Context context = new Context();
            context.putVar("sheetNames", Arrays.asList("11","22","33"));
            context.putVar("employees", employees);
            JxlsHelper.getInstance().processTemplate(in, out, context);

        } catch (Exception ex) {
            ex.printStackTrace();

        }


    }
}
